<!-- 
	* 摘要：订单管理
	* 软件名称：雪克码数据管理系统1.0
	* 文件名: tradeManagement.vue
	* 版本：1.0
 -->
<template>
	<div class="sn-common-container">
		<div class="trade-contianer">
			<header>
				<div class="sn-flex sn-row-center hidden-sm-and-down">
					<el-select v-model="searchShop"  placeholder="选择店铺"  clearable filterable style="width: 160px;margin-right: 10px;"  @change="currentChange(1)">
						<el-option v-for="item in shopList"
							:key="item.id"
							:label="item.name"
							:value="item.id">
						</el-option>
					</el-select>
					<el-input v-model="searchValue" placeholder="客户名称筛选" style="width: 150px;margin-right: 10px;" clearable
						@keyup.enter.native="currentChange(1)" />
					<el-input v-model="searchItem" placeholder="商品名称筛选" style="width: 150px;margin-right: 10px;" clearable
						@keyup.enter.native="currentChange(1)" />
					<el-select v-model="orderStatus" value-key="" style="width: 120px;margin-right: 10px;"  placeholder="订单状态" clearable filterable  @change="currentChange(1)">
						<el-option v-for="item in orderStatusList"
							:key="item.value"
							:label="item.label"
							:value="item.value">
						</el-option>
					</el-select>
					<el-date-picker v-model="BeginTime" type="datetime" style="margin-right: 10px; width: 150px;" placeholder="开始时间"  @change="currentChange(1)"></el-date-picker>
					<el-date-picker v-model="EndTime" type="datetime" placeholder="结束时间" style="width: 150px;"  @change="currentChange(1)"></el-date-picker>
					<el-button class="sn-btn" style="margin-left: 10px" type="primary" icon="el-icon-search"
						@click="currentChange(1)">
						搜索
					</el-button>
					<el-button class="sn-btn" style="margin-left: 10px" type="primary" icon="el-icon-download"
						@click="exportTradeFn()">
						导出
					</el-button>
					<el-button class="sn-btn" style="margin-left: 10px" type="primary" icon="el-icon-plus"
						@click="enterTradeDialog = true">
						录入订单
					</el-button>
				</div>
				<div class="hidden-sm-and-up">
					<el-input v-model="searchValue" placeholder="输入商品名称进行筛选" style="width: 200px" clearable
						@keyup.enter.native="currentChange(1)" />
					<el-button style="margin-left: 4px" type="primary" class="sn-btn" icon="el-icon-search"
						@click="currentChange(1)">
						搜索
					</el-button>
				</div>
			</header>
			<section> 
				<global-table :loading="tableLoading" style="margin-top: 20px;" :pageIndex="currentPage" :pageSize="pageSize" :headerData="initData"
					:data="tabelData" :isFullScreen="false" :operateW="200">
					<template #creatorRealname="scope">
						<span>姓名：{{ scope.row.creatorRealname||'未实名' }}</span> <br  />
						<span>昵称：{{ scope.row.creatorNickname||'未设置昵称' }}</span>
					</template>
					<template #createdTime="scope">
						<span>{{ $parseTime(scope.row.createdTime) }}</span>
					</template>
					<template #operate="scope">
						<el-button type="primary" size="mini" @click="openDetailsFn(scope.row.id)">详情</el-button>
						<el-button type="warning" size="mini" @click="openDeliveryFn(scope.row)">修改</el-button>
					</template>
				</global-table>
			</section>
			<footer style="margin-top: 10px;">
				<el-pagination @current-change="currentChange" :current-page.sync="currentPage" :page-size="pageSize"
					layout="prev, pager, next, jumper" :pager-count="7" class="sn-pagination" hide-on-single-page
					style="text-align: center;" :total="totalNum" background>
					>
				</el-pagination>
			</footer>
		</div>
		 <!-- 订单详情 -->
		 <el-dialog :visible.sync="tradeDialog" append-to-body class="sn-default-dialog" width="660px" @close="tradeDialogClose()">
			<div class="sn-title" slot="title">订单详情</div>
			<div v-loading="tradeDetailsLoading">
				<p class="sn-flex">
					<span>畅捷通编号：</span>
					<span>{{ tradeDetailsInfo.externalVoucherCode }}</span>
				</p>
				<p class="sn-flex">
					<span>订单编号：</span>
					<span>{{ tradeDetailsInfo.shanNiangTradeNo }}</span>
				</p>
				<p class="sn-flex" v-if="tradeDetailsInfo.itemType === 0">
					<span>客户：</span>
					<span>{{ tradeDetailsInfo.customerName}}</span>
				</p>
				<p class="sn-flex">
					<span>下单时间：</span>
					<span>{{  $parseTime(tradeDetailsInfo.tradeCreateTime) }}</span>
				</p>
				<p class="sn-flex">
					<span>地址：</span>
					<span>{{ tradeDetailsInfo.deliveryAddress }}</span>
				</p>
				<p class="sn-flex">
					<span>物流方式：</span>
					<span>{{ tradeDetailsInfo.distributionMode }}</span>
				</p>
				<p class="sn-flex">
					<span>备注：</span>
					<span>{{ tradeDetailsInfo.deliveryRemarks||'无' }}</span>
				</p>
				<global-table :showNumber="false"  :showOperate="false" :loading="itemTableLoading" style="margin-top: 20px;" :pageIndex="itemPage" :pageSize="itemPageSize" :headerData="itemInitData"
					:data="itemTabelData" :isFullScreen="false" :operateW="280">
					<template #quantity="scope">
						<span>{{ scope.row.distributeQuantity +'/' +scope.row.quantity}}</span>
					</template>
					<template #distributable="scope">
						<el-switch v-model="scope.row.distributable" active-color="#13ce66" inactive-color="#ff4949" :active-value="true" :inactive-value="false" @change="distributableFn(scope.row)">
						</el-switch>
					</template>
				</global-table>
				<el-pagination @current-change="itemPageChange" :current-page.sync="itemPage" :page-size="itemPageSize"
					layout="prev, pager, next, jumper" :pager-count="7" class="sn-pagination" hide-on-single-page
					style="text-align: center;" :total="itemTotal" background>
					>
				</el-pagination>
			</div>
		</el-dialog>
		  <!-- 发货窗口 -->
		<el-dialog :visible.sync="deliveryDialog" append-to-body class="sn-default-dialog" width="360px" @close="deliveryDialogClose()">
			<div class="sn-title" slot="title">修改订单状态</div>
			<div v-loading="deliveryLoading">
				<div class="sn-flex enter-item">
					<p><span class="sn-must-label">所属店铺：</span></p>
					<el-select v-model="deliveryInfo.enterpriseId"  placeholder="请选择订单所属店铺"  filterable style="width: 200px;margin-right: 10px;" >
						<el-option v-for="item in shopList"
							:key="item.id"
							:label="item.name"
							:value="item.id">
						</el-option>
					</el-select>
					<!-- <el-input v-model="enterTradeInfo.customerName" placeholder="请输入客户名称" size="normal" clearable style="width: 300px;"></el-input> -->
				</div>
				<div class="sn-flex" style="margin:20px 0;">
					<p>订单状态：</p>
					<el-select v-model="deliveryInfo.status"   placeholder="订单状态"  filterable >
						<el-option v-for="item in orderStatusList"
							:key="item.value"
							:label="item.label"
							:value="item.value">
						</el-option>
					</el-select>
				</div>
				<p style="text-align: center;">
					<el-button type="primary" size="medium" class="sn-btn" @click="tradeDeliveryFn()">保存</el-button>
					<el-button size="medium" @click="deliveryDialog = false">取消</el-button>
				</p>
			</div>
		</el-dialog>
		<el-dialog
		:visible.sync="enterTradeDialog"
		append-to-body
		:close-on-click-modal="false"
		width="600px"
		class="sn-default-dialog"
		@close="enterTradeDialogClose()"
		>
		<div class="sn-title" slot="title">录入订单</div>
		<div v-loading="enterTradeLoading" class="enter-trade-list">
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">选择店铺：</span></p>
				<el-select v-model="enterTradeInfo.enterpriseId"  placeholder="请选择订单所属店铺"  filterable style="width: 300px;margin-right: 10px;" >
					<el-option v-for="item in shopList"
						:key="item.id"
						:label="item.name"
						:value="item.id">
					</el-option>
				</el-select>
			</div>
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">客户名称：</span></p>
				<el-select
					v-model="enterTradeInfo.customerId"
					collapse-tags
					filterable
					:remote-method="getFillterShopFn"
					:loading="fillterShopLoading"
					remote
					placeholder="请输入客户名称"
					clearable
					style="width: 300px;"
				>
					<el-option v-for="item in fillterShopList" :key="item.id" :label="item.name" :value="item.id" />
				</el-select>
				<!-- <el-input v-model="enterTradeInfo.customerName" placeholder="请输入客户名称" size="normal" clearable style="width: 300px;"></el-input> -->
			</div>
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">闪酿订单编号：</span></p>
				<div class="sn-flex">
					<el-input v-model="enterTradeInfo.shanNiangTradeNo" placeholder="请输入闪酿订单号" size="normal" clearable style="width: 220px;margin-right: 10px;"></el-input>
					<el-button type="primary" size="medium" class="sn-btn" @click="getTradeDetailsFn()">查询</el-button>
				</div>
			</div>	
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">闪酿下单时间：</span></p>
				<el-date-picker v-model="enterTradeInfo.tradeCreateTime" type="datetime"  placeholder="请选择闪酿下单时间"  style="width: 300px;"></el-date-picker>
			</div>	
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">畅捷通订单编号：</span></p>
				<el-input v-model="enterTradeInfo.externalVoucherCode" placeholder="请输入畅捷通订单号" size="normal" clearable style="width: 300px;"></el-input>
			</div>
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">畅捷通单据日期：</span></p>
				<el-date-picker v-model="enterTradeInfo.externalVoucherDate" type="datetime"  placeholder="请选择畅捷通单据日期"  style="width: 300px;"></el-date-picker>
			</div>
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">订单状态：</span></p>
				<el-select v-model="enterTradeInfo.status"  style="width: 300px;" placeholder="订单状态"  filterable >
					<el-option v-for="item in orderStatusList"
						:key="item.value"
						:label="item.label"
						:value="item.value">
					</el-option>
				</el-select>
			</div>
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">收货人名称：</span></p>
				<el-input v-model="enterTradeInfo.consignee" placeholder="请输入收货人姓名" size="normal" clearable style="width: 300px;"></el-input>
			</div>
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">收货人手机号：</span></p>
				<el-input v-model="enterTradeInfo.consigneePhoneNumber" placeholder="请输入收货人手机号" size="normal" clearable style="width: 300px;"></el-input>
			</div>
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">收货地址：</span></p>
				<el-input v-model="enterTradeInfo.deliveryAddress" placeholder="请输入收货地址" size="normal" clearable style="width: 300px;"></el-input>
			</div>
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">物流方式：</span></p>
				<el-input v-model="enterTradeInfo.distributionMode" placeholder="请输入物流方式" size="normal" clearable style="width: 300px;"></el-input>
			</div>
			<div class="sn-flex enter-item">
				<p><span class="sn-must-label">订单商品明细：</span></p>
				<el-button type="info" size="mini" @click="plusItemDialog= true" class="sn-btn" icon="el-icon-plus">添加商品</el-button>
				
			</div>
			<div v-if="enterTradeInfo.tradeOrderItems.length>0">
				<global-table :showNumber="false"  :headerData="pushItemInitData"
					:data="enterTradeInfo.tradeOrderItems" :isFullScreen="false" :operateW="100">
					<template #quantity="scope">
						<span>{{ scope.row.quantity}}</span>
					</template>
					<template #operate="scope" >
						<el-button type="danger" size="mini" @click="deleteItemFn(scope)">删除</el-button>
					</template>
				</global-table>
			</div>
			<p style="text-align:center;margin-bottom: 0;">
				<el-button type="primary" size="medium" class="sn-btn" @click="enterTradeFn()">录入订单</el-button>
				<el-button size="medium" @click="enterTradeDialog = false">取消</el-button>
			</p>
		</div>
		</el-dialog>
		<el-dialog
		:visible.sync="plusItemDialog"
		width="375px"
		class="sn-default-dialog"
		append-to-body
		@close="closePlusItemDialogFn"
		>
		<div class="sn-title" slot="title">添加商品</div>
		<div>
			<div class="sn-flex" style=" margin-bottom: 20px;">
				<p class="sn-must-label">商品名称：</p>
				<el-select
						v-model="enterTradeInfoItem.itemName"
						filterable
    					allow-create
						remote
						clearable
						reserve-keyword
						style="width: 250px;"
						placeholder="请输入商品名称"
						@change="chooseItemChange"
						:remote-method="remoteMethod"
						:loading="loading">
						<el-option
						v-for="item in itemList"
						:key="item.id"
						:label="item.name"
						:value="item.name">
						</el-option>
					</el-select>
			</div>
			<div class="sn-flex" style=" margin-bottom: 20px;">
				<p class="sn-must-label">商品规格：</p>
				<el-input v-model="enterTradeInfoItem.specifications" placeholder="请输入商品规格" size="normal" clearable style="width: 250px;"></el-input>
			</div>
			<div class="sn-flex">
				<p class="sn-must-label">商品数量：</p>
				<el-input-number v-model="enterTradeInfoItem.quantity" size="normal" 
					:min="1" :max="9999999" :step="1" :controls="true" controls-position="both">
				</el-input-number>
			</div>
			<p style="text-align:center;margin-bottom: 0;">
				<el-button type="primary" size="medium" class="sn-btn" @click="pushItemFn()">保存</el-button>
				<el-button size="medium" @click="plusItemDialog = false">取消</el-button>
			</p>
		</div>
		</el-dialog>
	</div>
</template>
  
<script>
import GlobalTable from '@/components/GlobalTable';
import {  GetEnterprisesByPage} from '@/api/enterprise';
import {Get,GetTradeOrderItemsByPage,ChangeTradeStatus,GetTradeByPage,ExploreSearchResultToExcel,AddTrade,ToggleDistributable,GetCustomersPage,GetTradeFromShanNiang} from '@/api/trade';
import { guid } from '@/utils';
import { GetItemsPage} from '@/api/itemList';

export default {
	components: { GlobalTable },
	data() {
		return {
			plusItemDialog:false,
			tableLoading:false,
			tabelData: [],
			orderStatus:'',
			itemTypeText:['实物商品','卡密兑换','充值兑换','客调兑换'],
			orderStatusList:[
			{
				value:0,
				label:'已作废',
			},
			{
				value:1,
				label:'待配货',
			},{
				value:2,
				label:'待发货',
			},{
				value:3,
				label:'已发货',
			},{
				value:4,
				label:'已完成',
			}
		],
			initData: [
				{
					label: '客户',
					value: 'customerName',
					id: guid(),
					width: 200,
				},
				{
					label: '订单日期',
					value: 'tradeDate',
					id: guid(),
					width: 100,
				},
				{
					label: '商品种类',
					value: 'typeQuantity',
					id: guid(),
					width:100,
				},
				{
					label: '商品数量',
					value: 'totalQuantity',
					id: guid(),
					width: 100,
				},
				{
					label: '配货人',
					value: 'dispenserName',
					id: guid(),
					width: 100,
				},
				{
					label: '发货人',
					value: 'consignorName',
					id: guid(),
					width: 100,
				},
				
				{
					label: '订单处理状态',
					value: 'statusDescription',
					id: guid(),
				},
			],
			itemPage:1,
			itemPageSize:10,
			itemTableLoading:false,
			itemTabelData:[],
			itemTotal:0,
			itemInitData:[
			{
					label: '商品',
					value: 'itemName',
					id: guid(),
					width: 200,
				},
				{
					label: '规格',
					value: 'specifications',
					id: guid(),
					width: 170,
				},
				{
					label: '数量',
					value: 'quantity',
					id: guid(),
					width: 150,
					isCustom:true
				},
				{
					label: '配货',
					value: 'distributable',
					id: guid(),
					width: 80,
					isCustom:true
				},
			],
			pushItemInitData:[
			{
					label: '商品',
					value: 'itemName',
					id: guid(),
					width: 200,
				},
				{
					label: '规格',
					value: 'specifications',
					id: guid(),
					width: 150,
				},
				{
					label: '数量',
					value: 'quantity',
					id: guid(),
					width: 80,
					isCustom:true
				},
			],
			currentPage: 1,
			pageSize: 10,
			totalNum: 0,
			searchValue: '',
			searchItem:'',
			BeginTime:'',
			EndTime:'',
			tradeDetailsLoading:false,
			tradeDialog:false,
			tradeDetailsInfo:{},
			deliveryDialog:false,
			deliveryLoading:false,
			deliveryInfo:{
				status:0,
				enterpriseId:''
			},
			tradeStrogeId:'',
			enterTradeInfo:{
				tradeOrderItems:[]
			},
			enterTradeDialog:false,
			enterTradeLoading:false,
			shopList:[],
			searchShop:'',
			enterTradeInfoItem:{
				quantity:1,
				specifications:''
			},
			itemList:[],
			loading:false,
			fillterShopList:[],
			fillterShopLoading:false,
			fillterShop:'',
		}
	},
	created() {
		this.getShopListFn();
		this.getDataListFn();
	},
	methods: {
		async getTradeDetailsFn(){
			this.enterTradeLoading = true;
			let params = {
				EnterpriseId:this.enterTradeInfo.enterpriseId,
				TradeNo:this.enterTradeInfo.shanNiangTradeNo
			}
			const res = await GetTradeFromShanNiang(params);
			console.log(res);
			this.enterTradeLoading = false;
			if(res.code === 200){
				if(this.fillterShopList.length === 0){
					this.fillterShopList = [
						{
							id:res.data.customerId,
							name:res.data.customerName
						}
					];
				}
				this.enterTradeInfo = _.cloneDeep(res.data);
			}else{
				this.$message.error(res.erroMessage);
			}
		},
		// 获取筛选店铺数据
		async getFillterShopFn(query){	
			this.fillterShopLoading = true;
			let params = {
				pageIndex: 1,
				pageSize: 1000,
				Name:query,
			}
			const res = await GetCustomersPage(params);
			this.fillterShopLoading = false;
			if(res.code == 200){
				this.fillterShopList = res.data.list;
			}else{
				this.$message.error(res.message);
			}
		},
		async enterTradeFn(){
			if(!this.enterTradeInfo.enterpriseId){
				this.$message.error('订单所属企业不得为空');
				return;
			}
			// if(!this.enterTradeInfo.customerName){
			// 	this.$message.error('客户不得为空');
			// 	return;
			// }
			if(!this.enterTradeInfo.customerId){
				this.$message.error('客户不得为空');
				return;
			}
			let index = this.fillterShopList.findIndex(item=>item.id === this.enterTradeInfo.customerId);
			this.enterTradeInfo.customerName = this.fillterShopList[index].name;
			if(!this.enterTradeInfo.shanNiangTradeNo){
				this.$message.error('闪酿订单号不得为空');
				return;
			}
			if(!this.enterTradeInfo.externalVoucherCode){
				this.$message.error('畅捷通单据号不得为空');
				return;
			}
			if(!this.enterTradeInfo.tradeCreateTime){
				this.$message.error('闪酿下单时间不得为空');
				return;
			}
			if(!this.enterTradeInfo.externalVoucherDate){
				this.$message.error('畅捷通推送时间不得为空');
				return;
			}
			if(!this.enterTradeInfo.status){
				this.$message.error('订单状态不得为空');
				return;
			}
			if(!this.enterTradeInfo.consignee){
				this.$message.error('收货人姓名不得为空');
				return;
			}
			if(!this.enterTradeInfo.consigneePhoneNumber){
				this.$message.error('收货人联系电话不得为空');
				return;
			}
			if(!this.enterTradeInfo.deliveryAddress){
				this.$message.error('收货人地址不得为空');
				return;
			}
			if(!this.enterTradeInfo.distributionMode){
				this.$message.error('物流方式不得为空');
				return;
			}
			if(!this.enterTradeInfo.tradeOrderItems.length){
				this.$message.error('订单商品不得为空');
				return;
			}
			this.enterTradeLoading = true;
			const res = await AddTrade(this.enterTradeInfo);
			this.enterTradeLoading = false;
			if(res.code === 200){
				this.$message.success('添加成功');
			}else{
				this.$message.error(res.erroMessage);
			}
		},
		// 添加订单商品
		pushItemFn(){
			if(!this.enterTradeInfoItem.itemName){
				this.$message.error('商品名称不得为空');
				return;
			}
			if(!this.enterTradeInfoItem.specifications){
				this.$message.error('商品规格不得为空');
				return;
			}
			this.enterTradeInfo.tradeOrderItems.push({...this.enterTradeInfoItem});
			this.plusItemDialog = false;
		},
		closePlusItemDialogFn(){
			this.enterTradeInfoItem = {
				quantity:1
			};
		},
		enterTradeDialogClose(){
			this.enterTradeInfo = {
				tradeOrderItems:[]
			};
		},
		deleteItemFn(data){
			this.enterTradeInfo.tradeOrderItems.splice(data.index,1);
		},
		chooseItemChange(val){
			let index = this.itemList.findIndex(item=>item.name === val);
			if(index>=0){
				this.enterTradeInfoItem.itemId = this.itemList[index].id;
				this.enterTradeInfoItem.itemImageUrl = this.itemList[index].imageUrl;
				this.enterTradeInfoItem.specifications = this.itemList[index].specification;
				
			}else{
				delete this.enterTradeInfoItem.itemId;
				delete this.enterTradeInfoItem.itemImageUrl;
			}
			console.log(this.enterTradeInfoItem);
		},
		async remoteMethod(query) {
			if (query !== '') {
				this.loading = true;
				const res = await GetItemsPage({
					Name:query,
					pageSize:999,
					pageIndex:1
				});
				this.loading = false;
				if(res.code === 200){
					this.itemList = res.data.list;
				}else{
					this.itemList = [];
				}
			} else {
				this.itemList = [];
			}
		},
		async getShopListFn() {
			this.tableLoading = true;
			let params = {
				pageIndex: 1,
				pageSize: 999,
			}
			try {
				const res = await GetEnterprisesByPage(params);
				this.tableLoading = false;
				if (res.code === 200) {
					this.shopList = res.data.list;
					//this.searchShop = res.data.list[2].id;
				} else {
					this.shopList = [];
					this.$message.error('获取店铺列表失败，错误信息：' + res.erroMessage);
				}
			} catch (error) {
				this.tableLoading = false;
			}
		},
		// 导出订单
		async exportTradeFn(){
			try {
				this.tableLoading = true;
				let params = {
					pageIndex: this.currentPage,
					pageSize: this.pageSize,
				}
				if(this.orderStatus!=='') params.Status = this.orderStatus;
				if(this.searchValue!== '') params.CustomerName = this.searchValue;
				if(this.searchItem!== '') params.ItemName = this.searchItem;
				if(this.BeginTime) params.StartTime = this.BeginTime;
				if(this.EndTime) params.EndTime = this.EndTime;
				const res = await ExploreSearchResultToExcel(params);
				this.tableLoading = false;
				if (res.code!==500) {
					this.$message.success("订单导出成功，正在下载...");
					let blob = new Blob([res], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
					if ("download" in document.createElement("a")) {
						// 非IE下载
						const elink = document.createElement("a");
						// let fileName= window.decodeURI(res.headers['content-disposition'].split('=')[1], "UTF-8")
						let fileName = `订单列表`;
						elink.target = "hrefTemplate";
						elink.download = fileName;
						elink.href = URL.createObjectURL(blob);
						elink.click();
						URL.revokeObjectURL(elink.href); // 释放URL 对象
					} else {
						// IE10+下载
						navigator.msSaveBlob(blob, fileName);
					}
				} else {
					this.$message.error('导出箱码失败，错误信息：' + res.erroMessage);
				}
			} catch (error) {
				this.tableLoading = false;
				this.$message.error('导出箱码失败，错误信息：' + error);
			}
		},
		// 订单发货
		async tradeDeliveryFn(){
			this.deliveryLoading = true;
			const res = await ChangeTradeStatus(this.deliveryInfo);
			this.deliveryLoading = false;
			if(res.code === 200){
				this.$message.success('修改订单成功');
				this.deliveryDialog = false;
				this.getDataListFn();
			}else{
				this.$message.error('修改订单失败，错误信息：'+res.erroMessage); 
			}
		},
		// 关闭发货弹窗
		deliveryDialogClose(){
			this.deliveryInfo = {
				status:0,
				enterpriseId:'',
			}; 
		},
		// 打开发货弹窗
		openDeliveryFn(data,type){
			this.deliveryInfo.id = data.id;
			this.deliveryInfo.status = data.status;
			this.deliveryInfo.enterpriseId = data.enterpriseId;
			this.deliveryDialog = true;
		},
		// 关闭详情弹窗
		tradeDialogClose(){
			this.tradeDetailsInfo = {};
		},
		// 打开订单详情弹窗
		async openDetailsFn(id){
			this.tradeDialog = true;
			this.tradeDetailsLoading = true;
			const res = await Get({tradeId:id});
			this.tradeDetailsLoading = false;
			if(res.code === 200){
				this.tradeDetailsInfo = res.data;
				this.tradeStrogeId = id;
			}else{
				this.$message.error('获取订单详情失败,错误信息：'+res.erroMessage);
			}
			this.getItemsByTrade(id);
		},
		async getItemsByTrade(id){
			this.itemTableLoading = true;
			let params = {
				pageIndex: this.itemPage,
				pageSize: this.itemPageSize,
				tradeId: id,
			}
			const res = await GetTradeOrderItemsByPage(params);
			this.itemTableLoading = false;
			if(res.code === 200){
				this.itemTabelData = res.data.list;
				this.itemTotal = res.data.totalCount;
			}else{
				this.itemTabelData = [];
				this.$message.error('获取订单商品列表失败,错误信息：'+res.erroMessage);
			}
		},
		async distributableFn(data){
			this.itemTableLoading = true;
			const res = await ToggleDistributable({id:data.id, tradeId:this.tradeStrogeId});
			this.itemTableLoading = false;
			if(res.code === 200){
				this.$message.success('修改商品可装配状态成功');
				this.getItemsByTrade(this.tradeStrogeId);
			}else{
				this.$message.error('修改商品可装配状态失败，错误信息：'+res.erroMessage);
			}
		},
		itemPageChange(val){
			this.itemPage = val;
			this.getItemsByTrade(this.tradeStrogeId);
		},
		currentChange(val) {
			this.currentPage = val;
			this.getDataListFn();
		},
		// 获取订单列表
		async getDataListFn() {
			this.tableLoading = true;
			try {
				let params = {
					pageIndex: this.currentPage,
					pageSize: this.pageSize,
				}
				if(this.searchShop!=='') params.enterpriseId = this.searchShop;
				if(this.orderStatus!=='') params.Status = this.orderStatus;
				if(this.searchValue!== '') params.CustomerName = this.searchValue;
				if(this.searchItem!== '') params.ItemName = this.searchItem;
				if(this.BeginTime) params.StartTime = this.BeginTime;
				if(this.EndTime) params.EndTime = this.EndTime;
				const res = await GetTradeByPage(params);
				this.tableLoading = false;
				if (res.code === 200) {
					this.tabelData = res.data.list;
					this.totalNum = res.data.totalCount;
				} else {
					this.tabelData = [];
					this.$message.error('获取订单列表失败，错误信息：' + res.erroMessage);
				}
			} catch (error) {
				this.tableLoading = false;
				this.$message.error('请求订单列表失败，错误信息：' + error);
			}
			
		},
	}
};
</script>
  
<style lang="scss" scoped>
.trade-contianer {
	box-sizing: border-box;
	padding: 20px;
	background-color: #fff;
	
}
.enter-trade-list{
		.enter-item{
			margin-bottom: 10px;
			>p{
				width: 130px;
				text-align: right;
			}
		}
	}
</style>